<template>
  <view class="main">
    <view class="title">职业考试调查问卷</view>
    <view>
      <view class="surveyCard">
        <view class="cardTitle">
          <span class="isRequired"> * </span>
          1、您从事岗位的工作年限
        </view>
        <view>
          <u-radio-group wrap size="40" v-model="value">
            <u-radio
              @change="radioChange(item.value)"
              v-for="(item, index) in list"
              :key="index"
              :name="item.name"
              :disabled="item.disabled"
            >
              {{ item.name }}
            </u-radio>
          </u-radio-group>
        </view>
      </view>
      <view class="surveyCard">
        <view class="cardTitle">
          <span class="isRequired"> * </span>
          2、您是否参加过考前培训
        </view>
        <view>
          <u-radio-group wrap size="40">
            <u-radio
              @change="radioGroupChangeTwo(item.value)"
              v-for="(item, index) in listTwo"
              :key="index"
              :name="item.name"
              :disabled="item.disabled"
            >
              {{ item.name }}
            </u-radio>
          </u-radio-group>
        </view>
      </view>
      <view class="surveyCard" v-if="subjectTwo === 1">
        <view class="cardTitle">
          <span class="isRequired"> * </span>
          3、培训机构名称
        </view>
        <view>
          <u-input v-model="name" :type="type" :border="true" />
          <!-- <u-field border-top v-model="mobile"  placeholder="请输入" /> -->
        </view>
      </view>
      <view class="surveyCard" v-if="subjectTwo === 1">
        <view class="cardTitle">
          <span class="isRequired"> * </span>
          4、培训时长
        </view>
        <view>
          <u-radio-group wrap size="40">
            <u-radio
              @change="radioGroupChangeFour(item.value)"
              v-for="(item, index) in listFour"
              :key="index"
              :name="item.name"
              :disabled="item.disabled"
            >
              {{ item.name }}
            </u-radio>
          </u-radio-group>
        </view>
      </view>
      <view class="surveyCard" v-if="subjectTwo === 1">
        <view class="cardTitle">
          <span class="isRequired"> * </span>
          5、培训费用
        </view>
        <view>
          <u-input v-model="cost" :type="number" :border="true" />
          <!-- <u-field border-top v-model="mobile"  placeholder="请输入" /> -->
        </view>
      </view>
      <view class="surveyCard" v-if="subjectTwo === 1">
        <view class="cardTitle">
          <span class="isRequired"> * </span>
          6、培训满意度
        </view>
        <view class="rateStyle">
          <u-rate
            :count="count"
            v-model="countValue"
            @change="rateChange"
            size="40"
            gutter="15"
            active-color="#EA9200"
            inactive-color="#b2b2b2"
          />
        </view>
      </view>
      <view class="surveyCard">
        <view class="submitBtn">
          <u-button type="primary" shape="circle" @click="submitSurvey"
            >确认提交</u-button
          >
        </view>
      </view>
    </view>
  </view>
</template>

<script>
// 接口文件引入
import request from "@/pagesB/common/js/request/userInfo.js";
export default {
  // 页面数据
  data() {
    return {
      list: [
        {
          name: "1-3年",
          disabled: false,
          value: 1,
        },
        {
          name: "3-5年",
          disabled: false,
          value: 2,
        },
        {
          name: "5-10年",
          disabled: false,
          value: 3,
        },
        {
          name: "10年以上",
          disabled: false,
          value: 4,
        },
      ],
      listTwo: [
        {
          name: "是",
          disabled: false,
          value: 1,
        },
        {
          name: "否",
          disabled: false,
          value: 2,
        },
      ],
      listFour: [
        {
          name: "1天",
          disabled: false,
          value: 1,
        },
        {
          name: "2天",
          disabled: false,
          value: 2,
        },
        {
          name: "3天",
          disabled: false,
          value: 3,
        },
        {
          name: "3天以上",
          disabled: false,
          value: 4,
        },
      ],
      subjectOne: "",
      subjectTwo: "",
      name: "",
      subjectFour: "",
      cost: "",
      subjectRate: "",
      count: 5,
      examObj: {},
    };
  },

  onLoad(options) {
    // 获取临时缓存信息
    const examObj = { ...options };
    this.examObj = examObj;
    // examNumber = JSON.parse(options.examNumber);
    // idCard = JSON.parse(decodeURIComponent(options.idCard));
    // userName = JSON.parse(decodeURIComponent(options.name));
    // console.log(" 接收参数：", examNumber,idCard,userName);
  },

  // 页面显示
  onShow() {},

  // 分享到聊天
  onShareAppMessage() {},

  // 页面事件
  methods: {
    radioChange(e) {
      this.subjectOne = e;
    },
    radioGroupChangeTwo(e) {
      this.subjectTwo = e;
    },
    radioGroupChangeFour(e) {
      this.subjectFour = e;
    },
    rateChange(e) {
      this.subjectRate = e;
    },

    submitSurvey() {
      let question = [];
      if (!this.subjectOne) {
        uni.$u.toast("请检查问题是否填写完整!");
        return;
      }
      if (!this.subjectTwo) {
        uni.$u.toast("请检查问题是否填写完整!");
        return;
      }
      if (this.subjectTwo === 1) {
        if (!this.name) {
          uni.$u.toast("请检查问题是否填写完整!");
          return;
        }
        if (!this.subjectFour) {
          uni.$u.toast("请检查问题是否填写完整!");
          return;
        }
        if (!this.cost) {
          uni.$u.toast("请检查问题是否填写完整!");
          return;
        }
        if (!this.subjectRate) {
          uni.$u.toast("请检查问题是否填写完整!");
          return;
        }
        question = [
          {
            question_id: "1",
            type: "1",
            option_value: this.subjectOne,
          },
          {
            question_id: "2",
            type: "3",
            option_value: this.subjectTwo,
          },
          {
            question_id: "3",
            type: "2",
            option_value: this.name,
          },
          {
            question_id: "4",
            type: "1",
            option_value: this.subjectFour,
          },
          {
            question_id: "5",
            type: "2",
            option_value: this.cost,
          },
          {
            question_id: "6",
            type: "2",
            option_value: this.subjectRate,
          },
        ];
      } else if (this.subjectTwo === 2) {
        // uni.redirectTo({
        //     url: '/pages/learning/admissionTicket/index',
        //   });
        question = [
          {
            question_id: "1",
            type: "1",
            option_value: this.subjectOne,
          },
          {
            question_id: "2",
            type: "3",
            option_value: this.subjectTwo,
          },
        ];
      }
      const data = {
        examNumber: this.examObj.examNumber,
        idCard: this.examObj.idCard,
        name: this.examObj.name,
        question: question,
      };
      this.submitSurceyReq(data);
    },

    submitSurceyReq(data) {
	
      request.submitSurcey({
        data,
        success: (res) => {
			uni.showToast({
				title: '提交成功！',
				icon: 'success',
				mask: true
			})
          setTimeout(() => {
            uni.redirectTo({
              url: `/pages/learning/admissionTicket/index?examineeId=${this.examObj.examineeId}`,
            });
          }, 1500);
        },
        fail: (res) => {
        },
      });
    },
  },
};
</script>

<style lang="less">
.main {
  width: 100%;
  height: 100%;
  background-color: #f5f5f5;
  .title {
    width: 100%;
    height: 120rpx;
    line-height: 120rpx;
    text-align: center;
    font-size: 34rpx;
    font-weight: 600;
    color: #000000;
    background-color: #f5f5f5;
  }
  .surveyCard {
    width: 710rpx;
    // height: 382rpx;
    margin-left: 20rpx;
    margin-bottom: 20rpx;
    padding-left: 20rpx;
    padding-top: 30rpx;
    padding-bottom: 10rpx;
    border-radius: 12rpx;
    background-color: #fff;
    .cardTitle {
      margin-bottom: 10rpx;
      font-size: 30rpx;
      font-weight: bold;
      height: 35rpx;
      line-height: 35rpx;
      .isRequired {
        color: #ff4d4f;
      }
    }
    .u-radio {
      margin: 10rpx 0 10rpx 0;
    }
    .rateStyle {
      margin: 50rpx 0 50rpx 0;
    }
    .submitBtn {
      margin-bottom: 20rpx;
    }
  }
}
</style>
